package department.fc.controller;

import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class GetDepartmentController implements Controller{

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
	
		String departmentId = request.getParameter("departmentId");

		DepartmentService service = DepartmentService.getInstance();
		String url = null;
		try {
			Department department = service.getDepartmentById(departmentId);
			request.setAttribute("department", department);
			url = "/department_detail.jsp";
		} catch (SQLException e) {
			e.printStackTrace();
			request.setAttribute("error_message", e.getMessage());
			url = "/error.jsp";
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);

		
		return null;
	}

}
